package com.isunland.managesystem.ui;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.NavUtils;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.isunland.managesystem.R;
import com.isunland.managesystem.base.BaseVolleyActivity;
import com.isunland.managesystem.entity.EmployeeLoanContent;

public class DetailDepartmentCollectFragment extends Fragment {
  protected static final String EXTRA_VLAUE =
      "com.isunland.managesystem.ui.DetailDepartmentCollectFragment.EXTRA_VLAUE";
  private EmployeeLoanContent mContent;

  private TextView tvapplyTime;
  private TextView tvoccurDate;
  private TextView tvcertificateName;
  private TextView tvcertificateNo;
  private TextView tvexpenseDesc;
  private TextView tvaccname;
  private TextView tvamount;
  private TextView tvoutAmount;
  private TextView tvcontractName;
  //	private TextView tvifLoan;
  private TextView tvreceiverName;
  private TextView tvapplicantName;

  @Override public void onCreate(Bundle savedInstanceState) {
    setHasOptionsMenu(true);
    ((BaseVolleyActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    ((BaseVolleyActivity) getActivity()).getSupportActionBar().setTitle(R.string.detail_collect);
    //接收值
    mContent = (EmployeeLoanContent) getArguments().getSerializable(EXTRA_VLAUE);
    super.onCreate(savedInstanceState);
  }

  @Override public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case android.R.id.home:

        if (NavUtils.getParentActivityName(getActivity()) != null) {
          NavUtils.navigateUpFromSameTask(getActivity());
        }

        break;

      default:
        break;
    }
    return super.onOptionsItemSelected(item);
  }

  @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_detail_department_collect, container, false);
    initData(v);
    return v;
  }

  private void initData(View v) {
    tvapplyTime = (TextView) v.findViewById(R.id.tv_applyTime);
    tvoccurDate = (TextView) v.findViewById(R.id.tv_occurDate);
    tvcertificateName = (TextView) v.findViewById(R.id.tv_certificateName);
    tvcertificateNo = (TextView) v.findViewById(R.id.tv_certificateNo);
    tvexpenseDesc = (TextView) v.findViewById(R.id.tv_expenseDesc);
    tvaccname = (TextView) v.findViewById(R.id.tv_accname);
    tvamount = (TextView) v.findViewById(R.id.tv_amount);
    tvoutAmount = (TextView) v.findViewById(R.id.tv_outAmount);
    tvcontractName = (TextView) v.findViewById(R.id.tv_contractName);
    //		tvifLoan=(TextView) v.findViewById(R.id.tv_ifLoan);
    tvreceiverName = (TextView) v.findViewById(R.id.tv_receiverName);
    tvapplicantName = (TextView) v.findViewById(R.id.tv_applicantName);
    //初始化数据
    tvapplyTime.setText(mContent.getApplyTime());//填报日期
    tvoccurDate.setText(mContent.getOccurDate());//收支日期
    tvcertificateName.setText(mContent.getCertificateName());//收入支出类型
    tvcertificateNo.setText(mContent.getCertificateNo());//单据编号
    tvexpenseDesc.setText(mContent.getExpenseDesc());//费用摘要
            /*
             * 账户
			 */
    String accname = "";
    if (!TextUtils.isEmpty(mContent.getCertificateCode())) {
      String cerCode = mContent.getCertificateCode();
      if (cerCode.indexOf("DJLB-NBWLYFPYC-NBZWWL") > 0) {
        //判断账户是否选择,如果没有选择以支出为主
        accname = mContent.getPayerAccname();
      } else {
        if (!TextUtils.isEmpty(mContent.getPayeeAccount()) && (cerCode.indexOf("DJLB-CWSR") > 0
            || cerCode.indexOf("DJLB-TSSZ") > 0)) {
          accname = mContent.getPayeeAccname();
        }
        if (!TextUtils.isEmpty(mContent.getPayerAccount()) && (cerCode.indexOf("DJLB-CWZC") > 0
            || cerCode.indexOf("DJLB-TSSZ") > 0)) {
          accname = mContent.getPayerAccname();
        }
      }
    } else {
      accname = "";
    }

    tvaccname.setText(accname);

		/*
		 * 收入
		 */
    String inAmount = "";

    if (!TextUtils.isEmpty(mContent.getCertificateCode())) {
      String cerCode = mContent.getCertificateCode();
      if (cerCode.indexOf("DJLB-NBWLYFPYC-NBZWWL") > 0) {
        //判断账户是否选择,如果没有选择以支出为主
        if (!TextUtils.isEmpty(mContent.getPayeeAccount())) {
          inAmount = mContent.getInAmount();
        }
      } else {
        if ((cerCode.indexOf("DJLB-CWSR") > 0 || cerCode.indexOf("DJLB-TSSZ") > 0)) {
          inAmount = mContent.getInAmount();
        }
      }
    } else {
      inAmount = "";
    }
    tvamount.setText(inAmount);
		
		/*
		 * 支出
		 */

    String outAmount = "";
    if (!TextUtils.isEmpty(mContent.getCertificateCode())) {
      String cerCode = mContent.getCertificateCode();
      if (cerCode.indexOf("DJLB-NBWLYFPYC-NBZWWL") > 0) {
        if (!TextUtils.isEmpty(mContent.getPayerAccount())) {
          outAmount = mContent.getPoutAmount();
        }
      } else {
        if ((cerCode.indexOf("DJLB-CWZC") > 0 || cerCode.indexOf("DJLB-TSSZ") > 0)) {
          outAmount = mContent.getPoutAmount();
        }
      }
    } else {
      outAmount = "";
    }
    tvoutAmount.setText(outAmount);

    tvcontractName.setText(mContent.getContractName());//相关合同
    //		/*
    //		 * 是否完成还款
    //		 */
    //		String ifLoan="";
    //		if (!TextUtils.isEmpty(mContent.getIfReturnLoan())){
    //			if ("T".equals(mContent.getIfReturnLoan())){
    //				ifLoan="是";
    //			}else{
    //				ifLoan="否";
    //			}
    //		}else {
    //			ifLoan="";
    //		}
    //		tvifLoan.setText(ifLoan);
    //
    tvreceiverName.setText(mContent.getPartyName());//当事人
    tvapplicantName.setText(mContent.getApplicantName());//填报人
  }

  public static DetailDepartmentCollectFragment newInstence(EmployeeLoanContent content) {
    Bundle bundle = new Bundle();
    bundle.putSerializable(EXTRA_VLAUE, content);
    DetailDepartmentCollectFragment mfragment = new DetailDepartmentCollectFragment();
    mfragment.setArguments(bundle);
    return mfragment;
  }
}
